import machine
from machine import Pin
import time

KEY_IO = 0
LED_IO = Pin(2, Pin.OUT)    # led指示灯
key_pin_IO = Pin(KEY_IO, Pin.OUT)    # led指示灯
def button_callback(pin):
    # 按键按下时触发的动作
    print("key 0 press", LED_IO.value())
    if LED_IO.value() == 1:
        LED_IO.value(0)
    else:
        LED_IO.value(1)

def  key_init():
    button_pin = machine.Pin(KEY_IO, machine.Pin.IN, machine.Pin.PULL_UP)  # 替换为你连接的引脚
    button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_callback)

if __name__ == '__main__':
    key_init()
    while 1:
        time.sleep(1)
        key_st = key_pin_IO.value()
        print(key_st)


